﻿package mortal.game.view.mainUI.shortcutbar.panel
{
    import __AS3__.vec.*;
    import com.gengine.global.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.mui.controls.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.wizard.*;
    import mortal.game.view.wizard.data.*;
    import mortal.game.view.wizard.panel.*;
    import mortal.mvc.core.*;

    public class AngerBarPanel extends ToolTipSprite
    {
        private var _delayTimer:Timer;
        private var _xpSkillBar:GLoadedButton;
        private var _xpBtn:GLoadedButton;
        private var _xpBarBg:GBitmap;
        private var _label:GTextFiled;
        private var _spriteBox:Sprite;
        private var _posArr:Array;
        private var _spVec:Vector.<WizardXpItem>;
        private var _clip:AngerBar;
        private var _effectBoom:SWFPlayer;
        private var _effectFreeze:GBitmap;
        public var isShow:Boolean = false;
        public var _isOverBar:Boolean = false;
        private var _effectFire:SWFPlayer;

        public function AngerBarPanel()
        {
            this._posArr = [[-160, 0], [-120, -20], [-80, -40], [-40, -60], [0, -60], [40, -40], [80, -20], [120, 0]];
            this._spVec = new Vector.<WizardXpItem>;
            return;
        }// end function

        override protected function configUI() : void
        {
            this.mouseEnabled = true;
            this.mouseChildren = true;
            this._xpBtn = UIFactory.gLoadedButton(ImagesConst.XpBtn_upSkin, -4, 3, 69, 68, this);
            this._xpBtn.configEventListener(MouseEvent.CLICK, this.showWizard);
            this._xpBtn.name = "navUI_WizardBtn";
            this._xpBtn.toolTipData = this.getWizardToolTip;
            this._xpBarBg = UIFactory.gBitmap(ImagesConst.XpBarBg, -48, -22, this);
            this._spriteBox = new Sprite();
            this._spriteBox.x = -3;
            this._xpSkillBar = UIFactory.gLoadedButton(ImagesConst.XpSkillBtn_upSkin, 55, 10, 23, 22, null);
            this._xpSkillBar.configEventListener(MouseEvent.CLICK, this.showSprite);
            this._label = UIFactory.gTextField("", 7, 30, 50, 20, this, GlobalStyle.textFormatChen.center());
            this._label.mouseEnabled = false;
            this._clip = new AngerBar();
            this._clip.x = 31;
            this._clip.y = 36;
            this.addChildAt(this._clip, 0);
            this.updateAnger();
            this.creatSprite();
            this.addEventListener(MouseEvent.ROLL_OVER, this.showValue);
            this.addEventListener(MouseEvent.ROLL_OUT, this.showPerCent);
            return;
        }// end function

        private function getWizardToolTip()
        {
            var _loc_1:WizardData = null;
            var _loc_2:SkillInfo = null;
            if (!GameController.autoGuide.hasGuideWizard)
            {
                return Language.getString(35382);
            }
            _loc_1 = Cache.instance.wizard.fightWizardData;
            if (_loc_1)
            {
                _loc_2 = new SkillInfo();
                _loc_2.tSkill = SkillConfig.instance.getInfoById(_loc_1.tSpriteEx.xpskillId);
            }
            return _loc_2;
        }// end function

        private function showValue(event:MouseEvent) : void
        {
            this._isOverBar = true;
            this._label.text = int(Cache.instance.role.roleInfo.anger * 0.01).toString();
            return;
        }// end function

        private function showPerCent(event:MouseEvent) : void
        {
            this._isOverBar = false;
            var _loc_2:* = Cache.instance.role.roleInfo.anger;
            if (_loc_2 < 0)
            {
                _loc_2 = 0;
            }
            this._label.text = int(_loc_2 / WizardUtil.maxAnger * 100) + "%";
            return;
        }// end function

        public function updateAnger() : void
        {
            var _loc_1:* = Cache.instance.role.roleInfo.anger;
            var _loc_2:* = _loc_1 / WizardUtil.maxAnger * 100;
            if (_loc_1 < 0)
            {
                _loc_1 = 0;
            }
            if (this._isOverBar)
            {
                this._label.text = int(Cache.instance.role.roleInfo.anger * 0.01).toString();
            }
            else
            {
                this._label.text = _loc_2 + "%";
            }
            this._clip.gotoAndStop(_loc_2);
            this.updateEffect();
            return;
        }// end function

        private function mcMove() : void
        {
            this._clip.gotoAndStop((this._clip.frame + 1));
            return;
        }// end function

        private function creatSprite() : void
        {
            var _loc_3:WizardXpItem = null;
            var _loc_4:GBitmap = null;
            var _loc_5:Sprite = null;
            var _loc_6:int = 0;
            var _loc_1:* = Cache.instance.wizard.soulList;
            var _loc_2:* = _loc_1.length;
            while (_loc_6 < _loc_2)
            {
                
                _loc_5 = new Sprite();
                _loc_5.x = 50;
                _loc_5.y = 210;
                this._spriteBox.addChild(_loc_5);
                _loc_4 = UIFactory.gBitmap(ImagesConst.expLine, 0, 0, _loc_5);
                _loc_4.x = -_loc_4.width;
                _loc_4.y = -_loc_4.height;
                _loc_4.rotation = _loc_6 * 20 + 112;
                _loc_3 = new WizardXpItem();
                _loc_3.wizardData = _loc_1[_loc_6];
                _loc_3.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
                _loc_3.mouseChildren = false;
                _loc_3.mouseEnabled = true;
                _loc_3.buttonMode = true;
                _loc_3.isDragAble = false;
                _loc_3.addEventListener(MouseEvent.CLICK, this.selectSp);
                this._spriteBox.addChild(_loc_3);
                this._spVec.push(_loc_3);
                _loc_6++;
            }
            return;
        }// end function

        private function updateWizardList() : void
        {
            var _loc_1:WizardXpItem = null;
            for each (_loc_1 in this._spVec)
            {
                
                if (_loc_1.wizardData.isHasWizard)
                {
                    _loc_1.filters = [];
                    if (_loc_1.wizardData.tSprite.code == Cache.instance.wizard.fightWizardCode)
                    {
                        _loc_1.showEffect(true, -3, 20, "ArroundEffect.swf");
                    }
                    else
                    {
                        _loc_1.showEffect(false);
                    }
                    continue;
                }
                _loc_1.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

        public function updateSelected() : void
        {
            var _loc_1:WizardXpItem = null;
            for each (_loc_1 in this._spVec)
            {
                
                if (_loc_1.wizardData.isHasWizard)
                {
                    if (_loc_1.wizardData.tSprite.code == Cache.instance.wizard.fightWizardCode)
                    {
                        _loc_1.showEffect(true, -3, 20, "ArroundEffect.swf");
                        continue;
                    }
                    _loc_1.showEffect(false);
                }
            }
            return;
        }// end function

        private function showWizard(event:MouseEvent) : void
        {
            if (!GameController.autoGuide.hasGuideWizard)
            {
                return MsgManager.showRollTipsMsg(Language.getString(35383));
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.WizardUseXpSkill, null));
            return;
        }// end function

        private function showSprite(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (!GameController.autoGuide.hasGuideWizard)
            {
                return MsgManager.showRollTipsMsg(Language.getString(35383));
            }
            this.updateWizardList();
            if (!this._spriteBox.parent)
            {
                this.addChildAt(this._spriteBox, 0);
                event.stopImmediatePropagation();
                Global.stage.addEventListener(MouseEvent.CLICK, this.hideHandler);
                this._spriteBox.addEventListener(MouseEvent.ROLL_OUT, this.resetTimer);
                this._spriteBox.addEventListener(MouseEvent.MOUSE_OVER, this.mouseOverHandler);
                if (!this._delayTimer)
                {
                    this._delayTimer = new Timer(5000);
                    this._delayTimer.addEventListener(TimerEvent.TIMER, this.delayTimerHandler);
                    this._delayTimer.start();
                }
                else
                {
                    this._delayTimer.reset();
                    this._delayTimer.start();
                }
                _loc_2 = this._spVec.length;
                while (_loc_3 < _loc_2)
                {
                    
                    if (this._spVec[_loc_3])
                    {
                        this._spVec[_loc_3].x = 40;
                        this._spVec[_loc_3].y = -40;
                        TweenMax.to(this._spVec[_loc_3], 0.2, {x:this._posArr[_loc_3][0] + 40, y:this._posArr[_loc_3][1] - 40, ease:Quint.easeOut});
                    }
                    _loc_3++;
                }
            }
            return;
        }// end function

        private function hideHandler(event:MouseEvent = null) : void
        {
            this.isShow = false;
            removeChild(this._spriteBox);
            Global.stage.removeEventListener(MouseEvent.CLICK, this.hideHandler);
            this._spriteBox.removeEventListener(MouseEvent.ROLL_OUT, this.resetTimer);
            this._spriteBox.removeEventListener(MouseEvent.MOUSE_OVER, this.mouseOverHandler);
            this._delayTimer.stop();
            this._delayTimer.removeEventListener(TimerEvent.TIMER, this.delayTimerHandler);
            this._delayTimer = null;
            return;
        }// end function

        private function delayTimerHandler(event:TimerEvent) : void
        {
            this.hideHandler();
            return;
        }// end function

        private function resetTimer(event:MouseEvent) : void
        {
            this._delayTimer.delay = 1000;
            this._delayTimer.start();
            this._spriteBox.addEventListener(MouseEvent.MOUSE_OVER, this.mouseOverHandler);
            return;
        }// end function

        private function mouseOverHandler(event:MouseEvent) : void
        {
            this._delayTimer.stop();
            this._spriteBox.removeEventListener(MouseEvent.MOUSE_OVER, this.mouseOverHandler);
            return;
        }// end function

        private function selectSp(event:MouseEvent) : void
        {
            var _loc_2:* = (event.currentTarget as WizardXpItem).wizardData;
            if (_loc_2.isHasWizard)
            {
                if (_loc_2 == Cache.instance.wizard.fightWizardData)
                {
                    MsgManager.showRollTipsMsg(Language.getString(35384));
                }
                else
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.WizardSelectFight, _loc_2.code));
                }
            }
            else
            {
                MsgManager.showRollTipsMsg(Language.getString(35385));
            }
            return;
        }// end function

        public function get xpBtn() : GLoadedButton
        {
            return this._xpBtn;
        }// end function

        public function thawFrzzing() : void
        {
            if (this._effectFreeze)
            {
                this._effectFreeze.dispose(true);
                this._effectFreeze = null;
            }
            var _loc_1:* = Cache.instance.role.roleInfo.anger;
            if (_loc_1 == WizardUtil.maxAnger)
            {
                if (this._effectBoom == null)
                {
                    this._effectBoom = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
                    this._effectBoom.timeRate = 2;
                    this._effectBoom.playNum = 1;
                    this._effectBoom.addFrameScript(4, this.showFire);
                    this._effectBoom.actionPlayCompleteHandler = this.boomEnd;
                    this._effectBoom.load("angerBoom.swf", ModelType.NormalSwf, null);
                    this._effectBoom.move(233, 216);
                    this.addChild(this._effectBoom);
                }
            }
            else
            {
                if (this._effectBoom)
                {
                    this._effectBoom.dispose(true);
                    this._effectBoom = null;
                }
                if (this._effectFire)
                {
                    this._effectFire.dispose(true);
                    this._effectFire = null;
                }
            }
            return;
        }// end function

        private function updateEffect() : void
        {
            var _loc_1:int = 0;
            if (!GameController.autoGuide.hasGuideWizard)
            {
                if (this._effectFreeze == null)
                {
                    this._effectFreeze = UIFactory.gBitmap(ImagesConst.XpFrezzing, -57, -22, this);
                    this.addChild(this._effectFreeze);
                    this._xpSkillBar.visible = false;
                }
            }
            else
            {
                if (this._effectFreeze)
                {
                    this._effectFreeze.dispose(true);
                    this._effectFreeze = null;
                }
                this._xpSkillBar.visible = true;
                _loc_1 = Cache.instance.role.roleInfo.anger;
                if (_loc_1 == WizardUtil.maxAnger)
                {
                    if (this._effectBoom == null)
                    {
                        this._effectBoom = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
                        this._effectBoom.move(233, 216);
                        this._effectBoom.timeRate = 2;
                        this._effectBoom.playNum = 1;
                        this._effectBoom.addFrameScript(4, this.showFire);
                        this._effectBoom.actionPlayCompleteHandler = this.boomEnd;
                        this._effectBoom.load("angerBoom.swf", ModelType.NormalSwf, null);
                        this.addChild(this._effectBoom);
                    }
                }
                else
                {
                    if (this._effectBoom)
                    {
                        this._effectBoom.dispose(true);
                        this._effectBoom = null;
                    }
                    if (this._effectFire)
                    {
                        this._effectFire.dispose(true);
                        this._effectFire = null;
                    }
                }
            }
            return;
        }// end function

        private function boomEnd() : void
        {
            if (this._effectBoom)
            {
                this._effectBoom.dispose(true);
                this._effectBoom = null;
            }
            return;
        }// end function

        private function showFire() : void
        {
            var _loc_1:* = Cache.instance.role.roleInfo.anger;
            if (_loc_1 >= WizardUtil.maxAnger)
            {
                if (this._effectFire == null)
                {
                    this._effectFire = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
                    this._effectFire.move(38, 16);
                    this._effectFire.timeRate = 2;
                    this._effectFire.load("angerFull.swf", ModelType.NormalSwf, null);
                    this.addChild(this._effectFire);
                }
            }
            else if (this._effectFire)
            {
                this._effectFire.dispose(true);
                this._effectFire = null;
            }
            return;
        }// end function

    }
}
